import { Column, Entity, Tree, TreeChildren, TreeParent } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { BaseEntity } from '@/common/common/entity/base.entity';

@Entity({ name: 'sys_dept' })
@Tree('materialized-path')
export class SysDept extends BaseEntity {
  @Column()
  @ApiProperty({ description: '部门名称' })
  name: string;

  @Column({ nullable: true, default: 0 })
  @ApiProperty({ description: '排序' })
  orderNo: number;

  @Column({ nullable: true, default: null })
  @ApiProperty({ description: 'id' })
  parentId: string | number | null;

  // @Column({ nullable: true, default: [] })
  // @ApiProperty({ description: 'ids' })
  // parentIds?: [] | null;

  @TreeChildren({ cascade: true })
  children!: SysDept[];

  @TreeParent({ onDelete: 'SET NULL' })
  parent?: SysDept | null;

  // 状态 0:禁用 1：启用
  @Column({ default: 1, type: 'tinyint' })
  status: number;

}
